package com.kla.power.mapper;

import com.kla.power.entity.InverterDcAmountEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 直流电 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2024-06-10
 */
@Mapper
public interface InverterDcAmountMapper extends BaseMapper<InverterDcAmountEntity> {

    /**
     * 查询单个逆变器直流电发电历史数据
     * @param inverterDcAmountEntity
     * @return
     */
    @Select ( value = "<script>SELECT * FROM inverter_dc_amount_info iai " +
            "<trim prefix=\"WHERE\" prefixOverrides=\"and | or\">" +
            "<if test='inverterDcAmountEntity.inverterSn!=null'> AND iai.inverterSn=#{inverterDcAmountEntity.inverterSn} </if>" +
            " AND date_format(iai.createTime, '%Y-%m-%d') &gt;= date_format(#{inverterDcAmountEntity.startTime}, '%Y-%m-%d') AND date_format(iai.createTime, '%Y-%m-%d') &lt;= date_format(#{inverterDcAmountEntity.endTime}, '%Y-%m-%d') " +
            "</trim></script>" )
    List<InverterDcAmountEntity> queryHistoryData( @Param ( "inverterDcAmountEntity" ) InverterDcAmountEntity inverterDcAmountEntity );

    /**
     * 通过逆变器SN查询最新的直流电发电数据
     * @param inverterDcAmountEntity
     * @return
     */
    @Select(value = "SELECT * FROM (SELECT * FROM inverter_dc_amount_info where inverterSn=#{inverterDcAmountEntity.inverterSn}) idi\n" +
            "where idi.createTime= " +
            "      (select max(id.createTime) from (select * from inverter_dc_amount_info where inverterSn=#{inverterDcAmountEntity.inverterSn}) id) ORDER BY idi.sort")
    List<InverterDcAmountEntity> queryMaxDateList ( @Param ( "inverterDcAmountEntity" ) InverterDcAmountEntity inverterDcAmountEntity );


}
